package mao.thinkinjava.concurency.myenum;

import java.util.Random;

enum Outcome{WIN,LOSE,DRAW}
interface Item {
    Outcome compete(Item it);
    Outcome eval(Paper p);
    Outcome eval(Scissor s);
    Outcome eval(Rock r);
}
 class Paper implements Item {
     @Override
     public Outcome compete(Item it) {
         return it.eval(this);
     }

     @Override
     public Outcome eval(Paper p) {
         return Outcome.DRAW;
     }

     @Override
     public Outcome eval(Scissor s) {
         return Outcome.WIN;
     }

     @Override
     public Outcome eval(Rock r) {
         return Outcome.LOSE;
     }

     @Override
     public String toString() {
         return "Paper";
     }
 }

 class Rock implements Item{

     @Override
     public Outcome compete(Item it) {
         return it.eval(this);
     }

     @Override
     public Outcome eval(Paper p) {
         return Outcome.WIN;
     }

     @Override
     public Outcome eval(Scissor s) {
         return Outcome.LOSE;
     }

     @Override
     public Outcome eval(Rock r) {
         return Outcome.DRAW;
     }

     @Override
     public String toString() {
         return "Rock";
     }
 }

 class Scissor implements Item{

     @Override
     public Outcome compete(Item it) {
         return it.eval(this);
     }

     @Override
     public Outcome eval(Paper p) {
         return Outcome.LOSE;
     }

     @Override
     public Outcome eval(Scissor s) {
         return Outcome.DRAW;
     }

     @Override
     public Outcome eval(Rock r) {
         return Outcome.WIN;
     }

     @Override
     public String toString() {
         return "Scissor";
     }
 }
public class Compete{
    public static Random random = new Random(47);
    public static Item randomItem(){
        int s = random.nextInt(3);
        switch(s){
            case 0:return new Paper();
            case 1:return new Scissor();
            case 2:return new Rock();
            default:return new Paper();
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Item a = randomItem();
            Item b = randomItem();
            System.out.println(a+" vs "+b+" : "+a.compete(b));
        }
    }

}
